package com.wyu.servlet;

import com.wyu.service.CGService;
import com.wyu.service.CGServiceImpl;
import com.wyu.service.YGService;
import com.wyu.service.YGServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet("/CheckServlet")
public class CheckServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        String wpmc = request.getParameter("wpmc");
        String wpbh = request.getParameter("wpbh");
        String cgsl = request.getParameter("cgsl");
        String djr = request.getParameter("djr");
        System.out.println("物品名称:" + wpmc + ",物品编号:" + wpbh + ",采购数量:" + cgsl +",登记人:"+djr);
        CGService cgService = new CGServiceImpl();
        int cg = cgService.Checkwp(wpmc,wpbh,cgsl,djr);
        if (cg>0){
            response.sendRedirect("test.jsp");
            request.getSession().setAttribute("CheckMsg","登记成功");
        }else {
            request.getSession().setAttribute("CheckMsg","该物品已登记，不能重复登记！");
            response.sendRedirect("test.jsp");
        }

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request,response);
    }
}
